// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()

exports.main = async (event, context) => {
  const { id, openid } = event
  if (!id || !openid) {
    return { code: 1, msg: '参数不完整' }
  }
  try {
    // 只允许本人删除
    const bottle = await db.collection('bottles').doc(id).get()
    if (!bottle.data || bottle.data.openid !== openid) {
      return { code: 2, msg: '无权限删除' }
    }
    await db.collection('bottles').doc(id).remove()
    return { code: 0, msg: '删除成功' }
  } catch (e) {
    return { code: 3, msg: '数据库操作失败', error: e }
  }
} 